/**************************************************
 *	dOpSys Week-3
 *	Nikolas Bram & Dennis Thomasen
 *	20104278     & 20103903
 *	Thread implementation for the consumer
 *	producer exercise
 **************************************************/

#include <pthread.h>
#include <stdio.h>
#include <unistd.h>

#include "producer-consumer-list.h"

struct list *buffer;

void* consumer(void *arg){
	int i;
	for (i = 0; i < 0; i++) {
		sleep(2);
		printf("Consumer is using %d \n",i);
		remove_list(buffer);
		printf("Consumer is finished using %d \n",i);
	}
	return NULL;
}

int producer(){
	pthread_t threadb;
	int i;
	char chars[2];
	struct node *element;

	pthread_create(&threadb,NULL,consumer,NULL); //Creating new thread with the consumer method
	for (i = 0; i < 5; i++) {
		printf("Producer is putting %d in \n",i);
		printf(chars, "str %d", i);
		element = new_node_str(chars); //Assigning a new node to element
		add_list(buffer, element); //Adding the above element to the list
		sleep(1);
	}

	printf("Join haven't been done yet");
	//pthread_join(&threadb, NULL);
	printf("Join done");
	return 0;
}

int main(int argc, char *argv[])
{
	buffer = new_list();
	producer();
	return 0;
}
